import { ccs } from "../../util/services";
import { game } from "../control/game";
import { figureType, playerType, relationType,} from "../gameType";
import heroBase from "./heroBase";

export default class figureModel extends heroBase {

    figureInfo: relationType = {
        relation: null,
        id: 1,
        hero: null,
        intimate: 1,
    };
    
    constructor(relation: string, player?: playerType) {
        super(player);
        this.figureInfo.relation = relation;
        this.figureInfo.id = ccs.gf.randomId();
        this.figureInfo.hero = this.heroInfo;
        this.figureInfo.hero.id = ccs.gf.randomId();
    }
    //增加属性
    addInfo() {
        this.heroInfo.age ++;
        //升职 有一定的概率
        if(Math.random() > 0.3) {
            this.heroInfo.work.level ++;
        }
    }
    //花钱
    randomCost() {
        if(Math.random() >= 0.8) {
            let pay = 0;
            if(this.heroInfo.work) {
                pay = this.heroInfo.work.income * Math.random();
            } else {
                pay = this.heroInfo.money * Math.random();
                this.randomWork();
            }
            this.heroInfo.money -= pay;
            if(this.isFamily(this.heroInfo.id)) {
                game.recordMgr.addList({name: this.heroInfo.name, action: `剁手了，花了${pay}元`});
            }
        }
    }
    randomCeo(level: number, companyId: number) {
        let figureList = ccs.dataMgr.getFigure(0, 300);
        let index = Math.floor(Math.random()*299);
        let figure = figureList.find((val, i) =>  index == i);
        this.heroInfo.name = figure.name;
        this.heroInfo.age = figure.age;
        let comIndex =  ccs.dataMgr.getWorkIndex(companyId);
        //随机人物属性
        if(level == 1) {
            //人才市场
            //魅力 ，iq/200 +work.level/10)/2;
            //charm/100 + eq/200)/2;
            this.heroInfo.iq = ccs.gf.randomInt(70, 110);
            this.heroInfo.eq = ccs.gf.randomInt(70, 110);
            this.heroInfo.charm = ccs.gf.randomInt(1, 90);
            this.heroInfo.learn = ccs.gf.randomInt(1, 70);
            this.randomWork(ccs.gf.randomInt(1,6), comIndex);
        } else if(level == 2) {
            //校园招聘
            this.heroInfo.iq = ccs.gf.randomInt(70, 110);
            this.heroInfo.eq = ccs.gf.randomInt(80, 110);
            this.heroInfo.charm = ccs.gf.randomInt(0, 70);
            this.heroInfo.learn = ccs.gf.randomInt(50, 90);
            this.randomWork(ccs.gf.randomInt(1,4), comIndex);
        } else if(level == 3) {
            //猎头
            this.heroInfo.iq = ccs.gf.randomInt(70, 180);
            this.heroInfo.eq = ccs.gf.randomInt(70, 180);
            this.heroInfo.charm = ccs.gf.randomInt(30, 80);
            this.heroInfo.learn = ccs.gf.randomInt(30, 80);
            this.randomWork(ccs.gf.randomInt(3,7), comIndex);
        } else {
            //大公司挖人
            this.heroInfo.iq = ccs.gf.randomInt(80, 120);
            this.heroInfo.eq = ccs.gf.randomInt(80, 120);
            this.heroInfo.charm = ccs.gf.randomInt(40, 90);
            this.heroInfo.learn = ccs.gf.randomInt(40, 90);
            this.randomWork(ccs.gf.randomInt(4,9), comIndex);
        }
    }
    
}